import java.awt.Color;
import java.awt.Container;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

/**
 * 
 * @author Devin Wolanick
 * @Version 1.0
 * 
 * Counting Systems Display
 */
public class CountWindow {
	
	private String[] countTypes = {"Hi-Lo", "Hi-Opi", "Hi-Opii", "Zen", "Omegaii", "KO", "WizardA5"};
	private ArrayList<JPanel> panelList = new ArrayList<JPanel>();
	private int[] countSystems = new int[7];
	private int numPanels = 0;
	private JFrame countFrame;
	
	public CountWindow(int[] optionList) {
		JFrame countFrame = new JFrame("Counting Systems");
		this.countFrame = countFrame;
		countFrame.setVisible(false);
		countFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container pane = countFrame.getContentPane();
		pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
		
		//Find which systems to display
		for (int i=4; i<11; i++)
			if (optionList[i] ==1) {
				numPanels++;
				countSystems[i-4] = 1;
			}
		
		//Put selected systems into a list
		for (int i=0; i<numPanels; i++)
			panelList.add(new JPanel());
		
		//Set boarders on each systemPanel
		Border myBoarder = BorderFactory.createLineBorder(Color.black);
		for (int i=0; i<panelList.size(); i++)
			panelList.get(i).setBorder(myBoarder);
		
		//Set Labels and Add Panels
		int j = 0;
		for (int i=0; i<countSystems.length; i++)
			if (countSystems[i] == 1) {
				panelList.get(j).add(new JLabel(countTypes[i]+": 0"));
				pane.add(panelList.get(j));
				j++;
			}
		
		//Finalize
		countFrame.pack();
		countFrame.setResizable(false);
	}
	
	/**
	 * Displays current Counts
	 * @param myValues List of count Values
	 */
	public void takeValues(int[] myValues) {
		int j = 0;
		for (int i=0; i<countSystems.length; i++) {
			if (countSystems[i] == 1){
				panelList.get(j).removeAll();
				JLabel countLabel = new JLabel(countTypes[i]+": "+myValues[i]);
				if (myValues[i]>0) {
					countLabel.setBackground(Color.GREEN);
					panelList.get(j).setBackground(Color.GREEN);
				}
				else if (myValues[i]<0) {
					countLabel.setBackground(Color.RED);
					panelList.get(j).setBackground(Color.RED);
				}
				else {
					countLabel.setBackground(Color.WHITE);
					panelList.get(j).setBackground(Color.WHITE);
				}
				countLabel.setOpaque(true);
				panelList.get(j).add(countLabel);
				panelList.get(j).repaint();
				panelList.get(j).revalidate();
				j++;
			}
		}
	}
	
	public void setVisable (boolean myBool) {
		if (myBool == true)
			countFrame.setVisible(true);
		else
			countFrame.setVisible(false);
	}
}
